/**
 * 
 */
package cre.gutwo.handle;

import cre.gutwo.convert.Converter;
import cre.gutwo.domain.DataModel;
import cre.gutwo.imp.Imper;
import cre.gutwo.util.CsvUtils;
import cre.gutwo.util.FrameUtil;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author Cre.Gu
 *
 */
public class SwDataHandle extends DefaultDataHandle {

	@Resource
	private Imper swImp;
	@Resource
	private Converter swConverter;

	@Override
	public void handle(String orgiPath, String destPath, String type, Map<String, String> context) {
		try {
			FrameUtil.begin();
			// 源数据
			List<DataModel> orgiDatas = swImp.gainOrgiDatas(orgiPath, type, context);
			// print(orgiDatas);

			// 根据规则数据，转换源数据
			List<DataModel> destDatas = swConverter.convert(orgiDatas, type);
			swConverter.findSames(destDatas);

			// 生成csv文件
			String dest = gainDest(orgiPath, destPath);
			CsvUtils.writeCsvFile(destDatas, dest);
			FrameUtil.alert();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
